package com.manor.main.adapter;

import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.noober.background.drawable.DrawableCreator;
import com.manor.common.bean.UserNBean;
import com.manor.common.utils.DpUtil;
import com.manor.common.utils.StringUtil;
import com.manor.main.R;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * @version 1.0
 * @date 2020/6/18  14:05
 */
public class EvaluateAdapter extends BaseQuickAdapter<UserNBean.GoodBean, BaseViewHolder> {

    public EvaluateAdapter(int layoutResId, @Nullable List<UserNBean.GoodBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, UserNBean.GoodBean item) {
        helper.setText(R.id.tvText, StringUtil.isNotEmpty(item.getName())?item.getName():"无")
                .setText(R.id.tvNum, StringUtil.isNotEmpty(item.getNums())?item.getNums()+"次":"");

        if (StringUtil.isEmpty(item.getName())){
            setSolidX(helper.getView(R.id.tvText),Color.parseColor("#1affffff"));
        }else if (item.getType()!=0){
            if ("1".equals(item.getSex())){
                setSolid(helper.getView(R.id.tvText),Color.parseColor("#FFFF7373"),Color.parseColor("#FFC5B54B"));
            }else {
                setSolid(helper.getView(R.id.tvText),Color.parseColor("#FFFF73EC"),Color.parseColor("#FFDF84A5"));
            }


        }else {
            setSolidX(helper.getView(R.id.tvText),Color.parseColor("#4D5663"));
        }


    }



    public void setSolid(TextView tv, int startColor, int endColor) {
        Drawable drawable4 = new DrawableCreator.Builder()
                .setCornersRadius(DpUtil.dp2px(28))
                .setGradientAngle(0)
                .setGradientColor(startColor, endColor)
                .build();
        tv.setBackground(drawable4);
    }

    public void setSolidX(TextView tv,int solidColor) {
        Drawable drawable4 = new DrawableCreator.Builder()
                .setCornersRadius(DpUtil.dp2px(28))
                .setSolidColor(solidColor)
                .build();
        tv.setBackground(drawable4);
    }


}